package com.ai.demo.config;

import dev.langchain4j.model.openai.OpenAiChatModel;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.time.Duration;

/**
 * AUTHER: wangyue
 * TIME  : 2025/2/19 : 11:50
 */
@Configuration
public class OpenAIConfig {

    @Value("${openai.api-key}")
    private String apiKey;

    @Value("${openai.model}")
    private String model;

    @Value("${openai.temperature}")
    private double temperature;

    @Value("${openai.timeout}")
    private int timeout;

    @Value("${openai.baseurl}")
    private String baseurl;

    @Bean
    public OpenAiChatModel openAiChatModel() {
        return OpenAiChatModel.builder().baseUrl(baseurl)
                .apiKey(apiKey)
                .modelName(model)
                .temperature(temperature)
                .timeout(Duration.ofSeconds(timeout))
                .build();
    }
}